/*
 * @filename JpaUtils.java
 * @author barry
 * @version 0.0.1
 * @date 2019年12月9日
 */
package com.bnzj.core.persistence.util;

import com.bnzj.core.persistence.entity.BaseEntity;
import lombok.extern.slf4j.Slf4j;

import java.util.Date;

/**
 * @author barry
 * @date 2019-12-09
 */
@Slf4j
public class EntityUtils {

    public static <T extends BaseEntity> T saveBefore(T entity, String account, String name) {
        if (account == null || name == null) {
            log.warn("user is null");
            return entity;
        }
        if (entity.getId() == null) {
            entity.setCreator(account);
            entity.setCreatorName(name);
            entity.setModifyBy(account);
            entity.setModifyName(name);
            entity.setModifyTime(new Date());
            entity.setCreateTime(new Date());
        }
        if (entity.getId() != null) {
            entity.setModifyBy(account);
            entity.setModifyName(name);
            entity.setModifyTime(new Date());
        }
        return entity;
    }
}
